import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TActivePrevilege } from "../../../Message/Db/Tables/TActivePrevilege";
import { DateParser } from "../../common/tools/DateParser";
import { ClockManager } from "../manager/ClockManager";
type int = number;
//class ActivePrevilegeConfig
    
    export  class ActivePrevilegeConfig
    {
        constructor()
        {
            
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            if (ActivePrevilegeConfig._instance != null) 
            {
                throw new Error(" ActivityprivilegeConfig 单例 ");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_active_previlege.json");
            this.write(loc1);
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TActivePrevilege();
                loc1.id = loc2.id;
                loc1.name = loc2.name;
                loc1.type = loc2.type;
                loc1.giftCode = loc2.giftCode;
                loc1.giftAmount = loc2.giftAmount;
                loc1.value = loc2.value;
                loc1.costGold = loc2.costGold;
                loc1.awardCode = loc2.awardCode;
                loc1.awardAmount = loc2.awardAmount;
                loc1.minLevel = loc2.minLevel;
                loc1.maxLevel = loc2.maxLevel;
                loc1.startDt = DateParser.strToDateNormal(loc2.startDt);
                loc1.endDt = DateParser.strToDateNormal(loc2.endDt);
                this._map[loc1.id] = loc1;
            }
            return;
        }

        public getActivePrevilegeById(arg1: int): TActivePrevilege
        {
            return this._map[arg1];
        }

        public getActivePrevilegeArray(arg1: int): Array<any>
        {
            var loc2=null;
            var loc1=[];
            var loc3=0;
            var loc4=this._map;
            for(loc2 of loc4) 
            {
                if (!(arg1 >= loc2.minLevel && arg1 <= loc2.maxLevel && loc2.startDt.time <= ClockManager.instance.nowDate.time && loc2.endDt.time >= ClockManager.instance.nowDate.time)) 
                {
                    continue;
                }
                loc1.push(loc2);
            }
            return loc1;
        }

        public static get instance(): ActivePrevilegeConfig
        {
            if (ActivePrevilegeConfig._instance == null) 
            {
                ActivePrevilegeConfig._instance = new ActivePrevilegeConfig();
            }
            return ActivePrevilegeConfig._instance;
        }

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: ActivePrevilegeConfig;
    }
